/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "documents")
@XmlRootElement
public class Documents {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "docID")
    private Integer docid;
    @Basic(optional = false)
    @NotNull
    @Column(name = "docVersion")
    @Version
    private int version;
    @Basic(optional = false)
    @NotNull
    @Column(name = "docRevision")
    private int docrevision;
    @Size(min = 0, max = 250)
    @Column(name = "docDescription")
    private String docdescription;
    @Column(name = "docDate")
    @Temporal(TemporalType.DATE)
    private Date docdate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "docType")
    private int doctype;
    @Size(min = 0, max = 10)
    @Column(name = "docExtension")
    private String docextension;
    @Basic(optional = false)
    @NotNull
    @Column(name = "docData")
    private int docdata;
    @JoinColumn(name = "docPrev", referencedColumnName = "docID", nullable=true)
    @ManyToOne(optional = true)
    private Documents docprev;
    @OneToMany(mappedBy = "docprev")
    private Collection<Documents> docCollection;
    
    public Documents() {
    }

    public Documents(Integer docid) {
        this.docid = docid;
    }
    
    public Documents(Integer docid, int version, int docrevision, String docdescription, Date docdate, int doctype, String docextension, int docdata) {
        this.docid = docid;
        this.version = version;
        this.docrevision = docrevision;
        this.docdescription = docdescription;
        this.docdate = docdate;
        this.doctype = doctype;
        this.docextension = docextension;
        this.docdata = docdata;
    }

    public Integer getId() {
        return docid;
    }

    public void setId(Integer docid) {
        this.docid = docid;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public int getDocRevision() {
        return docrevision;
    }

    public void setDocRevision(int docrevision) {
        this.docrevision = docrevision;
    }
    
    public String getDocDescription(){
        return docdescription;
    }
    
    public void setDocDescription(String docdescription){
        if(docdescription!=null){
            this.docdescription = docdescription;
        }
    }

    public Date getDate() {
        return docdate;
    }

    public void setDate(Date docdate) {
        this.docdate = docdate;
    }

    public int getDocType() {
        return doctype;
    }

    public void setDocType(int doctype) {
        this.doctype = doctype;
    }
    
    public String getDocExt(){
        return docextension;
    }
    
    public void setDocExt(String docextension){
        if(!docextension.isEmpty()){
            this.docextension = docextension;
        }
    }

    public int getDocData() {
        return docdata;
    }

    public void setDocData(int docdata) {
        this.docdata = docdata;
    }

    public Documents getDocuments() {
        return docprev;
    }

    public void setDocuments(Documents docprev) {
        if(docprev != null && docprev.getId() != null){
            this.docprev = docprev;
        }
    }

    @XmlTransient
    public Collection<Documents> getDocumentsCollection() {
        return docCollection;
    }

    public void setDocumentsCollection(Collection<Documents> docCollection) {
        this.docCollection = docCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (docid != null ? docid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Beer)) {
            return false;
        }
        Documents other = (Documents) object;
        if ((this.docid == null && other.docid != null) || (this.docid != null && !this.docid.equals(other.docid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.Documents[ docID=" + docid + " ]";
    }
}
